<?php

/**
 * PHP versions 4 and 5
 * MagicPHP
 * Licensed under The Open Group Test Suite License
 * Redistributions of files must retain the above copyright notice.
 * @copyright:	Copyright 2011
 * @link:          
 * @package:    Model
 * @since:		MaginPHP 1.0
 * @license:	GNU General Public License (GPL)     
 */
?>
<?php
/**
 * @desc: Database Connection File 
 */
class Magic_Connection_Model {

    private $hostname;
    private $username;
    private $password;
    private $database;
    private $connect;
    private $select_db;
    private $config;
    private static $_instance; 
    /**
     * @desc: This is constructor to set the value for connection
     * @version: 1.0
     * @access: public 
     */
    public function __construct() {
        $this->config = CONFIG_PATH;
        $this->hostname = Magic_ReadIniFile_Model::callMethod()->readIniValue($this->config, "DATABASE", "hostname");
        
        $this->username = Magic_ReadIniFile_Model::callMethod()->readIniValue($this->config, "DATABASE", "username");
        if (Magic_ReadIniFile_Model::callMethod()->readIniValue($this->config, "DATABASE", "password") == 'null' || Magic_ReadIniFile_Model::callMethod()->readIniValue($this->config, "DATABASE", "password") == '') {
            $this->password = '';
        } else {
            $this->password = Magic_ReadIniFile_Model::callMethod()->readIniValue($this->config, "DATABASE", "password");
        }
        $this->database = Magic_ReadIniFile_Model::callMethod()->readIniValue($this->config, "DATABASE", "databasename");
    }
    public static function callMethod(){
        self::$_instance = new self ; 
        return self::$_instance;
        
    }

    /**
     * @desc: This function used to connect database
     * @version: 1.0 
     * @author: public
     */
    public function connectionOpen() {
        $this->connect = @mysql_connect($this->hostname, $this->username, $this->password);
        if (!$this->connect) {
            echo "Mysql Not Connected";
        } 
        $this->select_db = @mysql_select_db($this->database);
        if (!$this->select_db) {
            echo "Database Not Connected";
        } 
    }
    /**
     * @desc: This function is used to terminate the connection with database
     * @version: 1.0 
     * @access: public
     */
    public function connectionClose() {
        mysql_close($this->connect);
    }
}// end of Class 
?>